package com.ruoyi.web.controller.xcx;

import cn.hutool.core.util.ObjectUtil;
import com.ruoyi.common.annotation.ResultFilter;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.AInfor;
import com.ruoyi.system.domain.AInformation;
import com.ruoyi.system.domain.dto.XcxAInformationDTO;
import com.ruoyi.system.domain.vo.XcxAInformationVO;
import com.ruoyi.system.service.IAInforService;
import com.ruoyi.system.service.IAInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 分享类型详细Controller
 *
 * @author ruoyi
 * @date 2024-05-16
 */
@RestController
@RequestMapping("/xcx/aInformation")
public class XcxAInformation extends BaseController {

    @Autowired
    private IAInformationService aInformationService;
    @Resource
    private IAInforService aInforService;

    /**
     * 查询分享类型详细列表
     */
    /*@GetMapping ("/list")
    @ResultFilter
    public TableDataInfo list(XcxAInformationDTO inforDto)
    {
        List<XcxAInformationVO> list = aInformationService.selectAInformationXcxList(inforDto);
        return getDataTable(list);
    }*/

    /**
     * 当前分类及子分类关联的分享类型详细列表
     * listByInforId
     */
    @GetMapping ("/list")
    @ResultFilter
    public TableDataInfo list(XcxAInformationDTO inforDto) {
        Long inforId = inforDto.getInforId();
        if(ObjectUtil.isNotNull(inforId)){
            AInfor aInfor = new AInfor();
            aInfor.setAncestors(String.valueOf(inforId));
            List<AInfor> inforList = aInforService.selectAInforList(aInfor);
            List<Long> inforIdList = inforList.stream().map(AInfor::getId).collect(Collectors.toList());
            inforIdList.add(0, inforId);
            inforDto.setInforIdList(inforIdList);
            inforDto.setInforId(null);
        }

        List<XcxAInformationVO> list = aInformationService.selectAInformationXcxList(inforDto);
        return getDataTable(list);
    }

    /**
     * 获取素材库类别详细信息
     */
    @GetMapping(value = "/getXcxInfo")
    @ResultFilter
    public AjaxResult getXcxInfo(XcxAInformationDTO inforDto)
    {
        return success(aInformationService.selectAInformationXcxByinfor(inforDto));
    }

    /**
     * 获取素材库类别详细信息
     */
    @PostMapping(value = "/addXcxInfo")
    public AjaxResult addXcxInfo(@RequestBody AInformation inforDto)
    {
        return success(aInformationService.addXcxInfo(inforDto));
    }
}
